package com.itheima.stock.handler;

import com.itheima.stock.enums.CodeEnum;
import com.itheima.stock.exception.StockException;
import com.itheima.stock.response.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
 * @author by wym
 * @ Date 2022/2/14
 * @ Description
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = StockException.class)
    public ResponseResult<?> handleStockException(StockException e){
        return ResponseResult.error(e.getCode());
    }

    @SuppressWarnings("all")
    @ExceptionHandler(value = Exception.class)
    public ResponseResult<?> handleUnKnowException(Exception e) {
        log.error("系统异常", e);
        e.printStackTrace();
        return ResponseResult.error(CodeEnum.SYSTEM_ERROR);
    }
}
